package com.rabbit.order.controller;

import com.rabbit.order.domain.OrderVO;
import com.rabbit.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;
    @PostMapping("/create/{userId}")
    public ResponseEntity<String > createOrder(@RequestBody OrderVO orderVO,@PathVariable String userId){
        String orderId = orderService.createOrder(orderVO, userId);
        return  new ResponseEntity<>(orderId, HttpStatus.OK);
    }

    @PutMapping("/edit/{userId}")
    public ResponseEntity<String > editOrder(@RequestBody OrderVO orderVO,@PathVariable String userId){
        String s = orderService.payOrder(orderVO, userId);
        return  new ResponseEntity<>(s, HttpStatus.OK);
    }
    @GetMapping("/{userId}")
    public ResponseEntity<List<OrderVO>> getOrders(@PathVariable String userId){
        List<OrderVO> orders = orderService.getOrders(userId);
        return new ResponseEntity<>(orders, HttpStatus.OK);
    }
}
